//
//  Parser.h
//  ND91U
//
//  Created by 刘澎辉 on 12/13/13.
//  Copyright (c) 2013 nd. All rights reserved.
//

/**
网络字节流的解析器
*/
#import <Foundation/Foundation.h>

@interface Parser : NSObject

///-------------------------------
/// @name UInt -> data
///-------------------------------

+ (void)appendUInt8:(UInt8)value
                 to:(NSMutableData *)rawData;

+ (void)appendUInt16:(UInt16)value
                  to:(NSMutableData *)rawData;

+ (void)appendUInt32:(UInt32)value
                  to:(NSMutableData *)rawData;

+ (void)appendUInt64:(UInt64)value
                  to:(NSMutableData *)rawData;

///-------------------------------
/// @name data -> UInt
///-------------------------------

+ (UInt8)parseDataToUInt8:(NSData *)data;

+ (UInt16)parseDataToUInt16:(NSData *)data;

+ (UInt32)parseDataToUInt32:(NSData *)data;

+ (UInt64)parseDataToUInt64:(NSData *)data;

///-------------------------------
/// @name parse with location
///-------------------------------

+ (UInt8)parseDataToUInt8:(NSData *)data
                      loc:(NSUInteger *)loc;

+ (UInt16)parseDataToUInt16:(NSData *)data
                        loc:(NSUInteger *)loc;

+ (UInt32)parseDataToUInt32:(NSData *)data
                        loc:(NSUInteger *)loc;

+ (UInt64)parseDataToUInt64:(NSData *)data
                        loc:(NSUInteger *)loc;

+ (NSString *)parseDataToNSString:(NSData *)data
                              loc:(NSUInteger *)loc;

///-------------------------------
/// @name NSString -> data
///-------------------------------

+ (void)appendNSString:(NSString *)string
                    to:(NSMutableData *)rawData;

@end
